#pragma once
#include "d3dutil.h"
#include "LevelElement.h"
#include "Vertex.h"
#include "SearchCell.h"
#include "Building.h"
#include <vector>
using namespace std;

class CubePosColorNorm;
class ContentManager;

//-----------------------------------------------------
// Soldier Class									
//-----------------------------------------------------
class Soldier :public LevelElement
{
public:
	Soldier(const tstring &texfilename, float radius, int slices, int stacks, ContentManager* Manager, int life, int range, int damage);
	virtual ~Soldier(void);

	virtual void Initialize(ContentManager *pContentManager);
	virtual void Draw(const RenderContext* pRenderContext);
	virtual void OnTriggerEnter(LevelElement* element);

	void SetMaterialColor(float r, float g, float b, float a);
	void SetDynamic();
	void AddTime(float Time);
	void RemoveSphere();
	float GetTime();
	void SetPickup(bool Pickup);
	bool GetDeleted(){return m_DeleteOnlyOnce;}
	void SetID(int ID){m_ID = ID;}
	int GetID(){return m_ID;}
	void EraseTrigger();
	void SetPath(vector<D3DXVECTOR3*> path){m_pathToGoal =  path;}
	vector<D3DXVECTOR3*> GetPath(){return m_pathToGoal;};
	void Move();
	void FindPosition();
	bool SeeIfAvailable(NxVec3 Pos);
	void MoveToSpot(NxVec3 EndPos);
	void SetOpacity(float op){m_Opacity = op;};
	void IsAttacking(Building* Enemy);
	void IsAttacking(Soldier* Enemy);
	void Attack(float TimePassed);
	bool FoundTargetToAttack(){return m_IsAttacking;};
	float GetOpacity() {return m_Opacity;};
	void LoseLife(int Damage) {m_Life -= Damage;};
	void CreateEnemyBullet(D3DXVECTOR3 pos, float speed);
	void StopAttacking() {m_IsAttacking = false;};
	float GetRange(){return m_Range;};

	bool m_GotPath;
	bool m_GotDestination;
	bool m_IsAttacking;

protected:
	ID3D10InputLayout*			m_pVertexLayout;
	ID3D10Buffer*				m_pVertexBuffer;
	ID3D10Buffer*				m_pIndexBuffer;

	ID3D10Effect*				m_pDefaultEffect;
	ID3D10EffectTechnique*		m_pDefaultTechnique;

	ID3D10ShaderResourceView *	m_pTextureRV;

	ID3D10EffectMatrixVariable* m_pWorldViewProjectionVariable;
	ID3D10EffectMatrixVariable* m_pWorldVariable;
	ID3D10EffectVectorVariable* m_pLightDirVariabele;
	ID3D10EffectShaderResourceVariable* m_pDiffuseMapVariabele;

	float m_Opacity;
	float m_AttackTime;
	ID3D10EffectScalarVariable *m_OpacityVar;

	float m_Range, m_Damage;

	vector<VertexPosNormTex> m_VecVertices;
	vector<DWORD> m_VecIndices;
	tstring m_TextureName;
	float m_Radius;
	//slice is als een stuk taart, 
	//stack is als er taarten op elkaar zouden staan
	int m_NumSlices, m_NumStacks;
	float m_Time;
	Building* m_EnemyTargetBuilding;
	Soldier* m_EnemyTargetSoldier;

	//physX
	bool m_bStatic;
	
	NxActorDesc m_ActorDesc;
	NxBodyDesc m_BodyDesc;
	NxSphereShapeDesc m_SphereShapeDesc;

	void InitActor();
	bool m_Pickup;
	bool m_DeleteOnlyOnce;

	
	int m_ID;
	int m_Life;

	vector<CubePosColorNorm*> m_EnemyBulletList;

	NxActor *m_TriggerActor;
	NxActorDesc m_TriggerActorDesc;
	NxBoxShapeDesc m_TriggerShapeDesc;
	NxSphereShapeDesc m_TriggerSphereDesc;

	vector<D3DXVECTOR3*> m_pathToGoal;
	ContentManager* m_Manager;

	void CreateEffect(ContentManager *pContentManager);
	void GetEffectVariables(ID3D10Effect* pEffect);
	void DefineInputlayout();
	void BuildShape();
	void AddTriangle (unsigned int a, unsigned int b, unsigned c);
	void BuildVertexBuffer();
	void BuildIndexBuffer();
	
private:
	// -------------------------
	// Disabling default copy constructor and default assignment operator.
	// If you get a linker error from one of these functions, your class is internally trying to use them. This is
	// an error in your class, these declarations are deliberately made without implementation because they should never be used.
	// -------------------------
	Soldier(const Soldier& t);
	Soldier& operator=(const Soldier& t);

};
